<?php

namespace App\Admin\Controllers;

use App\Models\SysPolicy;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;

class SysPolicyController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new SysPolicy(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('type')->using(["1" => "系统推荐型", "2" => "高频型", "3" => "激进型", "4" => "稳健性", "5" => "保守型", "6" => "自定义", "7" => "系统推荐型2", "8" => "新手策略"]);
            $grid->column('first_number');
            $grid->column('size');
            $grid->column('limit_win_rate');
            $grid->column('limit_lose_rates');
            $grid->column('limit_lose_rate');
            $grid->column('back_win_rate');
            $grid->column('back_lose_rate');
            $grid->column('first_double')->using([0 => '否', 1 => '是']);
            $grid->column('cover_type')->using(['avg' => '均价补仓', 'last' => '按最后一手补仓价格补仓']);
            $grid->column('open_enable')->bool();
            $grid->column('close_enable')->bool();
            $grid->column('open_period');
            $grid->column('close_period');
            $grid->column('close_win_rate');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
            $grid->disableCreateButton();
            $grid->disableBatchActions();
            $grid->disableRowSelector();
            $grid->disableViewButton();
            $grid->disableDeleteButton();
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new SysPolicy(), function (Form $form) {
            $form->display('id');
            $form->select('type')->options(["1" => "系统推荐型", "2" => "高频型", "3" => "激进型", "4" => "稳健性", "5" => "保守型", "6" => "自定义", "7" => "系统推荐型2", "8" => "新手策略"])->readOnly();
            $form->decimal('first_number')->required();
            $form->number('size');
            $form->decimal('limit_win_rate');
            $form->list('limit_lose_rates')->min(10)->max(10)->required();
            $form->decimal('limit_lose_rate', '首次补仓跌幅');
            $form->decimal('back_win_rate');
            $form->decimal('back_lose_rate');
            $form->radio('first_double')->options([0 => '否', 1 => '是'])->required();
            $form->radio('cover_type')->options(['avg' => '均价补仓', 'last' => '按最后一手补仓价格补仓'])->required();
            $form->radio('open_enable')->options(['0' => '关', '1' => '开'])->required();
            $form->radio('open_period')->options(['1m' => '1m', '3m' => '3m', '5m' => '5m', '15m' => '15m', '30m' => '30m']);
            $form->text('close_enable')->options(['0' => '关', '1' => '开'])->required();
            $form->radio('close_period')->options(['1m' => '1m', '3m' => '3m', '5m' => '5m', '15m' => '15m', '30m' => '30m']);
            $form->decimal('close_win_rate');

            $form->footer(function ($footer) {
                // 去掉`查看`checkbox
                $footer->disableViewCheck();
                // 去掉`继续编辑`checkbox
                $footer->disableEditingCheck();
                // 去掉`继续创建`checkbox
                $footer->disableCreatingCheck();
            });
            $form->disableViewButton();
            $form->disableDeleteButton();
        });
    }
}
